package com.dzj.fishingcommunity.controller;

import com.dzj.fishingcommunity.common.ResponseResult;
import com.dzj.fishingcommunity.model.CoolFishSport;
import com.dzj.fishingcommunity.service.CoolFishSportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cool-fish-sports")
@Tag(name = "酷渔区域管理", description = "酷渔区域管理相关的接口")
public class CoolFishSportController {

    @Autowired
    private CoolFishSportService coolFishSportService;

    @Operation(summary = "获取所有酷渔区域")
    @GetMapping
    public ResponseResult<Page<CoolFishSport>> getAllCoolFishSports(
            @Parameter(description = "当前页码", required = false) @RequestParam(defaultValue = "1") int current,
            @Parameter(description = "每页大小", required = false) @RequestParam(defaultValue = "10") int size) {
        Pageable pageable = PageRequest.of(current - 1, size);
        Page<CoolFishSport> coolFishSportPage = coolFishSportService.getAllCoolFishSports(pageable);
        return ResponseResult.success(coolFishSportPage);
    }

    @Operation(summary = "根据ID获取酷渔区域")
    @GetMapping("/{id}")
    public ResponseResult<CoolFishSport> getCoolFishSportById(@PathVariable String id) {
        CoolFishSport coolFishSport = coolFishSportService.getCoolFishSportById(id);
        return ResponseResult.success(coolFishSport);
    }

    @Operation(summary = "新增酷渔区域")
    @PostMapping
    public ResponseResult<CoolFishSport> addCoolFishSport(@RequestBody CoolFishSport coolFishSport) {
        CoolFishSport addedCoolFishSport = coolFishSportService.addCoolFishSport(coolFishSport);
        return ResponseResult.success(addedCoolFishSport);
    }

    @Operation(summary = "更新酷渔区域")
    @PutMapping("/{id}")
    public ResponseResult<CoolFishSport> updateCoolFishSport(@PathVariable String id, @RequestBody CoolFishSport coolFishSport) {
        CoolFishSport updatedCoolFishSport = coolFishSportService.updateCoolFishSport(id, coolFishSport);
        return ResponseResult.success(updatedCoolFishSport);
    }

    @Operation(summary = "删除酷鱼运动")
    @DeleteMapping("/{id}")
    public ResponseResult<Void> deleteCoolFishSport(@PathVariable String id) {
        coolFishSportService.deleteCoolFishSport(id);
        return ResponseResult.success(null);
    }
}